//
//  ZHZTeachCtryVC.m
//  test
//
//  Created by 朱圳 on 2018/3/19.
//  Copyright © 2018年 朱圳. All rights reserved.
//

#import "ZHZTeachCtryVC.h"
#import "TeachCtryHead.h"
#import "TeachCtryCell.h"
#import "OrderModel.h"
@interface ZHZTeachCtryVC ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)NSMutableArray *stuArray;

@end

@implementation ZHZTeachCtryVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.xlTableView.dataSource = self;
    self.xlTableView.delegate = self;
    self.xlTableView.backgroundColor = [UIColor whiteColor];
    self.xlTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}

-(void)viewWillAppear:(BOOL)animated{
        [super viewWillAppear:animated];
    [self requestData];
}
-(void)requestData{
    __weak typeof(self) weakSelf = self;
    NSDictionary *dict = @{
                           @"gid" : Gid,
                           @"gpass" : Gpassword,
                           };
    [[AFNetworkTool shareManager]postJSONWithUrl:GR_Readylist parmas:dict successData:^(id json) {
        [self.stuArray removeAllObjects];
        NSArray *arr = json[@"data"];
        for (int i = 0; i<arr.count; i++) {
            OrderModel *model = [OrderModel yy_modelWithJSON:arr[i]];
            NSTimeInterval interval = [[NSDate date] timeIntervalSince1970];
            if ([model.endTime doubleValue]>interval &&[model.isornot isEqualToString:@"0"])  {
                [weakSelf.stuArray addObject: model];
            }
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakSelf.xlTableView reloadData];
        });
        
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
        [Utility showFail:@"网络错误"];
    }];
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.stuArray.count;
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    TeachCtryCell *cell = [tableView dequeueReusableCellWithIdentifier:@"teachCtryCell"];
    if (!cell) {
        cell = [[TeachCtryCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"teachCtryCell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = self.stuArray[indexPath.row];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    OrderModel *model = self.stuArray[indexPath.row];
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",model.sphone];
    UIWebView * callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self.view addSubview:callWebview];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}
/** 区头视图 */
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (self.stuArray.count>0) {
        TeachCtryHead *header = [[TeachCtryHead alloc] initWithReuseIdentifier:@"header"];
        return header;
    }else{
        return nil;
    }
}
#pragma mark - 懒加载
-(NSMutableArray *)stuArray{
    if (!_stuArray) {
        _stuArray = [[NSMutableArray alloc]init];
    }
    return _stuArray;
}

@end

